//cookie取出userId
var userId=getCookie("userId");
console.log(userId);
if(userId==null){//未登录
    alert("用户未登录")
    location.href="log_in.html";
}else {//登陆成功加载用户的笔记本
    $(function () {
        $.ajax({
            url: base_url + "/notebook/loadbooks.do",
            type: "get",
            data: {
                "userId": userId,
            },
            dataType: "json",
            success: function (data) {
                if (data.status == 0) {
                    var books = data.data;
                    for (var i = 0; i < books.length; i++) {
                        var bookId = books[i].noteBookId;
                        var bookName = books[i].noteBookName;
                        //动态拼接li标签内容,加到ul
                        var s_li = '<li class="online" >'
                        s_li += '<a id="bookName">'
                        s_li += '<i class="fa fa-book" title="online" rel="tooltip-bottom">'
                        s_li += '</i> ' + bookName
                        s_li += '</a>'
                        s_li += '</li>'
                        var $li = $(s_li)//将html字符串转换成jquery对象
                        $li.data("bookId", bookId)//将bookId绑定到li元素中
                        //将li元素添加到ul
                        $("#book_list").append($li)
                    }
                    return false;
                }

            },
            error: function () {
                alert("加载失败,稍后重试")
            }
        });
    })
}


